﻿/******************************************************************************
  * Copyright  2023 - LiuKuan
  * All right reserved. See COPYRIGHT for detailed Information.
  *
  * @file       SettingsHelper.h
  * @brief
  * @author     <807874484@qq.com>
  * @date       2024/07/29
  * @history
  *****************************************************************************/

#ifndef SETTINGSHELPER_H
#define SETTINGSHELPER_H


#include <QObject>
#include <QDir>
#include <QSettings>
#include <QMutex>
#include "Singleton.h"
#include "Stdafx.h"

class SettingsHelper : public QObject
{
    Q_OBJECT
    SINGLETON(SettingsHelper)
    Q_PROPERTY_READONLY_AUTO(QDir,rootDir);
    Q_PROPERTY_READONLY_AUTO(QString,appName);

public:
    explicit SettingsHelper(QObject *parent = nullptr);

    Q_INVOKABLE QStringList getDebuggerList();
    Q_INVOKABLE QString getCmdByKey(QString cmd);
    Q_INVOKABLE int  getNavigationViewMode();
    Q_INVOKABLE void saveNavigationViewMode(int mode);
    Q_INVOKABLE int  getDarkMode();
    Q_INVOKABLE void saveDarkMode(int mode);
    Q_INVOKABLE QString getLanguage();
    Q_INVOKABLE void saveLanguage(const QString &language);
    void save(const QString &key, QVariant val);
    QVariant get(const QString &key, QVariant def);
private:
    void     init_           ();
    void     createDefaultSettings_  (const QString &filePath);
    void     createGrounedSettings_  (const QString &file_path);
private:
    QString  rootDirPath_{};
    QString  hostName_{};
    QSettings *settings_{nullptr};
    QSettings *groundedSettings_{nullptr};
    QMutex mtx_;
signals:
};

#endif // SETTINGSHELPER_H
